package org.hot100_6.leetcode543;

import org.algorithm.Sort.MaxHeap;
import org.leetcode.TreeNode;

public class Solution {

    int res = 0;
    public int diameterOfBinaryTree(TreeNode root) {

        getMaxLength(root);
        return res;
    }


    public int getMaxLength(TreeNode root){
        if (root==null){
            return 0;
        }

        int left = getMaxLength(root.left);
        int right = getMaxLength(root.right);

        int currentLength = left+right;

        res = Math.max(res,currentLength);

        return Math.max(left,right)+1;
    }
}
